﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using MaxLeaf.Common;
using System.Data;
using MaxLeaf.DB;

namespace MaxLeaf.DAL
{
    public class t_departmentDALBuilder : BaseDALBuilder
    {
         
        public t_departmentDALBuilder()
            : base()
        {
            K3DAL =  new K3.t_departmentDAL();

            WebDAL = new Web.t_departmentDAL();

        }
        protected override bool ValidCheckOrgData(ServerInfo orgServer, DataRowView drvLog)
        {
            if (!orgServer.MasterDB)
            {
                //主账套分发
                return false;
            }
            if ((LogStatus)CvtFunc.ToInt(drvLog[DEL.LogDEL.LogStatus]) == LogStatus.Delete)
            {
                return true;
            }
            using (DBAccess dbOrgCon = new DBAccess(orgServer))
            {
                string strFItemId = CvtFunc.ToString(drvLog[DEL.LogDEL.KeyValue]);
                DataRow drOrgData = dbOrgCon.GetTableDataFirstRow("t_department", new Dictionary<string, object>() { { "FItemId", strFItemId } }, "FNumber");
                if (drOrgData == null)
                {
                    LogManager.Debug(string.Format("t_department {0} not exist", strFItemId));
                    return false;
                }

                //只分发4开头的
                if (!CvtFunc.ToString(drOrgData["FNumber"]).StartsWith("4.", StringComparison.InvariantCultureIgnoreCase)

                    )
                {

                    LogManager.Debug(string.Format("t_department {0} FNumber {1} 不分发", strFItemId, drOrgData["FNumber"]));
                    return false;
                }

            }

            return base.ValidCheckOrgData(orgServer, drvLog);
        }
        
    }
}